package com.chen.nongansampling.presenter;

import android.content.Context;
import android.util.Log;

import com.chen.nongansampling.bean.SampledListBean;
import com.chen.nongansampling.bean.request.GetSampledRequest;
import com.chen.nongansampling.manager.DataManager;
import com.chen.nongansampling.model.CallbackData;
import com.chen.nongansampling.presenterView.SampledView;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class SampledPresenter extends BasePresenter {
    private Context mContext;
    private SampledView sampledView;

    private CallbackData<List<SampledListBean>> callbackData;

    public SampledPresenter(Context context){
        this.mContext = context;
    }


    @Override
    public void onCreate() {

    }

    @Override
    public void onDestroy() {

    }
    @Override
    public void BindPresentView(Object presentView) {
        sampledView = (SampledView) presentView;
    }





    public void getSampledListResponseInfo(GetSampledRequest getSampledRequest) {    //获取人员名称
        DataManager.getInstance(mContext).getSampledListResponseInfo(getSampledRequest)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<CallbackData<List<SampledListBean>>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CallbackData<List<SampledListBean>> listCallbackData) {
                        callbackData = (CallbackData<List<SampledListBean>> )listCallbackData;

                    }
                    @Override
                    public void onError(Throwable e) {
                        sampledView.onError(e.toString());
                    }

                    @Override
                    public void onComplete() {
                        if (callbackData != null) {
                            sampledView.getSampledList(callbackData);
                            Log.d("qqqqqqqqqqqqqq",callbackData.toString());
                        }
       //                 SampledPresenter.super.compositeDisposable.dispose();
                    }
                });
    }




}
